package com.xiaoyudeguang.customizer;

import com.xiaoyudeguang.annotations.RequestMapping;
import org.springdoc.core.customizers.RouterOperationCustomizer;
import org.springdoc.core.fn.RouterOperation;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;

/**
 * @author 赵光
 */
@Component
public class CustomRouterOperationCustomizer implements RouterOperationCustomizer {

    @Override
    public RouterOperation customize(RouterOperation routerOperation, HandlerMethod handlerMethod) {
        RequestMapping requestMapping = handlerMethod.getMethod().getAnnotation(RequestMapping.class);
        if (requestMapping != null) {
            routerOperation.setConsumes(requestMapping.consumes());
            routerOperation.setProduces(requestMapping.produces());
            routerOperation.setMethods(requestMapping.method());
        }
        routerOperation.setBeanMethod(handlerMethod.getMethod().getName());
        routerOperation.setBeanClass(handlerMethod.getMethod().getDeclaringClass());
        return routerOperation;
    }
}
